import { reqGetGoodDetail, reqGetAddShopping} from "@/api";
import {getUUID} from '@/utils/uuid-tekon'
const actions={
    //获取商品详情
    async getGoodsDetail($store,skuId){
        let newObj=await reqGetGoodDetail(skuId);
        console.log(newObj.data);
        let result =newObj.data;
        $store.commit("GETGOODSDETAIL",result.data)
    },
    //添加商品到购物车  也可以修改商品数量
    async getAddShopping($store,shop){
        // console.log($store,shop);
        let result=await reqGetAddShopping(shop.skuId,shop.skuNum);
        // console.log(result)
        if (result.data.code==200) {
            return "ok";
        }else{
            return Promise.reject(new Error("fail"));
        }
    }
};
const mutations={
    GETGOODSDETAIL(state,result){
        state.goodsDetail=result;
        // console.log(result);
    }
};
const state={
    goodsDetail:{},
    uuid_tekon:getUUID()
};
const getters={
    categoryView:state=>state.goodsDetail.categoryView||{},
    skuInfo:state=>state.goodsDetail.skuInfo||{},
    spuSaleAttrList:state=>state.goodsDetail.spuSaleAttrList||{}
};
export default {
    actions,
    mutations,
    state,
    getters
}